
$(function(){
    var tableNavLi = $('.xg_table_nav li');
    tableNavLi.bind('click',function () {
        var _this = $(this);
        tableNavLi.removeClass('active');
        _this.addClass('active');
    });
});

//获取根路径
function getRootPath(){
    var curWwwPath=window.document.location.href;
    var pathName=window.document.location.pathname;
    var pos=curWwwPath.indexOf(pathName,9);
    var rootPath=curWwwPath.substring(0,pos);
    return(rootPath);
}

var rootPath = getRootPath();
// 导航
function createMenu(index){
    var $header = $('#j-header');
    var menuArr = [
        {
            'menuName':'<i class="fa fa-caret-right"></i>车次管理',
            'menuUrl':'ticket/holi_bus'
        },
        {
            'menuName':'<i class="fa fa-caret-right"></i>车次详情',
            'menuUrl':'ticket/holi_bus_detail'
        },
        {
            'menuName':'<i class="fa fa-caret-right"></i>订票详情',
            'menuUrl':'ticket/holi_ticket'
        },
        {
            'menuName':'<i class="fa fa-caret-right"></i>已订车票',
            'menuUrl':'ticket/holi_ticketed'
        },
        {
            'menuName':'<i class="fa fa-caret-right"></i>车次管理',
            'menuUrl':'ticket/work_bus'
        },
        {
            'menuName':'<i class="fa fa-caret-right"></i>班车详情',
            'menuUrl':'ticket/work_bus_detail'
        },
        {
            'menuName':'<i class="fa fa-caret-right"></i>订票详情 ',
            'menuUrl':'ticket/work_ticket'
        },
        {
            'menuName':'<i class="fa fa-caret-right"></i>已订车票',
            'menuUrl':'ticket/work_ticketed'
        },
        {
            'menuName':'<i class="fa fa-bus"></i><span>车辆管理</span>',
            'menuUrl':'ticket/busDetail'
        },
        {
            'menuName':'<span class="glyphicon glyphicon-user"></span><span>人员管理</span>',
            'menuUrl':'ticket/staff'
        },
        {
            'menuName':'<span class="glyphicon glyphicon-bullhorn"></span><span>通知管理</span>',
            'menuUrl':'ticket/notice'
        },
        {
            'menuName':'<span class="fa fa-users"></span><span>拼车拼玩</span>',
            'menuUrl':'ticket/carPooling'
        },
        {
            'menuName':'<i class="fa fa-pie-chart"></i><span>报表统计</span>',
            'menuUrl':'ticket/report'
        },
        {
            'menuName':'<i class="fa fa-address-card"></i><span>科室管理</span>',
            'menuUrl':'ticket/department'
        },
        {
            'menuName':'<i class="fa fa-commenting"></i><span>短信管理</span>',
            'menuUrl':'ticket/sms'
        },
        {
            'menuName':'<i class="fa fa-paper-plane-o" aria-hidden="true"></i><span>意见反馈</span>',
            'menuUrl':'ticket/feedback'
        }
    ];
    var lis = [];
    menuArr.forEach(function(item,key){
        lis.push('<li class="' + ((index==key+1)?' active':'') + '"><a href="' + rootPath + '/' + item.menuUrl + '">' + item.menuName + '</a></li>');
    });
    var menuDom ='<ul class="nav nav-pills nav-stacked nav-bracket">'
                 +'    <li class="nav-parent nav-parent1"><a href=""><span class="glyphicon glyphicon-tags"></span><span>假期班车管理</span></a>'
                 +'        <ul class="children" style="display: block">'
                 +              lis[0]+lis[1]+lis[2]+lis[3]
                 +'        </ul>'
                 +'    </li>'
                 +'    <li class="nav-parent nav-parent2"><a href=""><span class="glyphicon glyphicon-tag"></span><span>工作日班车管理</span></a>'
                 +'        <ul class="children" style="display: block">'
                 +              lis[5]+lis[6]+lis[7]
                 +'        </ul>'
                 +'    </li>'
                 +     lis[8]+lis[9]+lis[10]+lis[11]+lis[12]+lis[13]+lis[14]+lis[15]
                 +'</ul>';
    $header.html(menuDom);
    if(index<=4) {
        $('.nav-parent1').addClass('active');
    }
    else if(4<index && index<=8) {
        $('.nav-parent2').addClass('active');
    }
    else {}
}

